package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import lombok.Getter;

import java.util.Objects;

/**
 * 预警查询
 * @author haibin.zhang
 * @version v1.0
 * @date 2019/6/6 14:45
 * @since v1.0
 */
@Getter
public enum WarningSearchEnum {
    CHECKED_WAREHOUSE_ALL_LIMIT(FieldTypeEnum.CHECKED_WAREHOUSE_ALL_LIMIT.getType(),"enum.warningSearch.name.checked_warehouse_all_limit",FieldTypeEnum.CHECKED_WAREHOUSE_ALL_LIMIT),
    CHECKED_WAREHOUSE_UPPER_LIMIT(FieldTypeEnum.CHECKED_WAREHOUSE_UPPER_LIMIT.getType(),"enum.warningSearch.name.checked_warehouse_upper_limit",FieldTypeEnum.CHECKED_WAREHOUSE_UPPER_LIMIT),
    CHECKED_WAREHOUSE_LOWER_LIMIT(FieldTypeEnum.CHECKED_WAREHOUSE_LOWER_LIMIT.getType(),"enum.warningSearch.name.checked_warehouse_lower_limit",FieldTypeEnum.CHECKED_WAREHOUSE_LOWER_LIMIT),
    ;
    private Integer code;
    private String name;
    private FieldTypeEnum fieldTypeEnum;

    WarningSearchEnum(Integer code, String name, FieldTypeEnum fieldTypeEnum) {
        this.code = code;
        this.name = name;
        this.fieldTypeEnum = fieldTypeEnum;
    }

    public static FieldTypeEnum getWarnTypeEnum(Integer warnType){
            if (Objects.equals(warnType,1)){
                //分仓上限预警
                return CHECKED_WAREHOUSE_UPPER_LIMIT.fieldTypeEnum;
            }else if (Objects.equals(warnType,2)){
                //分仓下限预警
                return CHECKED_WAREHOUSE_LOWER_LIMIT.fieldTypeEnum;
            }else {
                //分仓全预警
                return CHECKED_WAREHOUSE_ALL_LIMIT.fieldTypeEnum;
            }
    }


    /**
     * 预警类型
     * @param fieldType
     * @return
     */
    public static Integer getWarnType(Integer fieldType) {
        if (Objects.equals(fieldType,CHECKED_WAREHOUSE_ALL_LIMIT.getCode())){
            //全预警
            return 0;
        }else if (Objects.equals(fieldType,CHECKED_WAREHOUSE_UPPER_LIMIT.getCode())){
            //上限
            return 1;
        }
        //下限
        return 2;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
